package com.tyj.gulimall.product.web;

import com.tyj.gulimall.product.entity.CategoryEntity;
import com.tyj.gulimall.product.service.CategoryService;
import com.tyj.gulimall.product.vo.web.Catalog2Vo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@Slf4j
public class IndexController {

    @Value("${server.port}")
    String port;

    @Autowired
    CategoryService categoryService;

    @RequestMapping({"/","index.html"})
    public String indexPage(Model model){
        //查询一级目录
        log.debug("端口号{}服务正在服务",port);
        List<CategoryEntity> categoryEntityList =categoryService.getLevel1Category();
        model.addAttribute("category",categoryEntityList);
        return "index";
    }

    @RequestMapping("/index/json/catalog.json")
    @ResponseBody
    public Map<String, List<Catalog2Vo>> getCatalogJson(){
        Map<String, List<Catalog2Vo>> map=categoryService.getCategoryJson();
        return map;
    }

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello";
    }
}

